package com.erp.erp_project.service.impl;

import com.erp.erp_project.mapper.WorkMapper;
import com.erp.erp_project.model.Work;
import com.erp.erp_project.service.WorkService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.regex.Pattern;

@Service
@AllArgsConstructor
public class WorkServiceImpl implements WorkService {
    private final WorkMapper workMapper;
    @Override
    public List<Work> list(Work work,Integer type,String va) {
        if(type!=null&&type==1){
            Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
            if(pattern.matcher(va).matches()&&va!=""){
                work.setId(Integer.parseInt(va));
            }
        }
        if(type!=null&&type==2){
            if(va!=null){
                work.setNumber(va);
            }
        }
        return workMapper.list(work);
    }

    @Override
    public void delete(int id) {
        workMapper.delete(id);
    }

    @Override
    public void add(Work work) {
        workMapper.add(work);
    }

    @Override
    public Work selectById(int id) {
        return workMapper.selectById(id);
    }

    @Override
    public void update(Work work) {
        workMapper.update(work);
    }

    @Override
    public Work selectByName(String name) {
        return workMapper.selectByName(name);
    }
}
